#include <iostream>
#include <iterator>
#include <vector>
#include <algorithm>

using std::cout;
using std::endl;
using std::cin;
using std::istream_iterator;
using std::ostream_iterator;
using std::vector;
using std::copy;

//定位在哪里出现了问题(cout大法、gdb)
//然后查找问题的原因
//
void test()
{
    vector<int> vec;
    vec.reserve(10);
    istream_iterator<int> isi(cin);
    /* cout << "222" << endl; */
    //向vector尾部添加元素push_back
    //std::back_inserter的底层会调用push_back
    /* copy(isi, istream_iterator<int>(), vec.begin()); */
    copy(isi, istream_iterator<int>(), std::back_inserter(vec));
    cout << "3333" << endl;
    cout << "size() = " << vec.size() << endl;
    cout << "capacity() = " << vec.capacity() << endl;

    //遍历vector
    copy(vec.begin(), vec.end(), 
         ostream_iterator<int>(cout, "  "));
    cout << endl;
}

int main(int argc, char *argv[])
{
    test();
    return 0;
}

